<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加项目</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
    <script src="../../js/lay-module/http/http.js"></script>
</head>
<body onload="initRole()">
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">部门名称</label>
        <div class="layui-input-block">
            <input type="text" name="name" lay-verify="required" lay-reqtext="部门名称不能为空" placeholder="请输入项目名称" value="" class="layui-input">
            <tip>部门名称不能和已有部门名重复</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">部门专项类资金</label>
        <div class="layui-input-block">
            <input type="text" name="money" placeholder="请输入部门专项类资金" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>

    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;


        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var index = layer.confirm("是否提交" + JSON.stringify(data.field), {
                title: '最终的提交信息'
            }, function () {
                console.log(JSON.stringify(data.field))
                // 执行保存操作
                $.ajax({
                    type: 'POST',
                    url: $api + 'projectLibrary/department/insert/department',
                    dataType: "json",
                    contentType: "application/json;charset=utf-8",
                    data: JSON.stringify(data.field),
                    async: false,
                    headers: {
                        'Authorization': layui.data('table')['Authorization']
                    },
                    success: function (res) {
                        identifyCode(res)
                        // 判断是否保存成功
                        if (!res.code) {
                            // 1.提示操纵成功
                            layer.msg(res.message)

                            // 2.关闭弹出层
                            layer.close(index);
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.location.reload();//刷新父页面，注意一定要在关闭当前iframe层之前执行刷新
                            parent.layer.close(iframeIndex);

                            // 3.重新加载上一层

                        }else {
                            layer.msg(res.message)
                        }
                    }
                });


            });

            return false;
        });

    });
</script>
</body>
</html>